﻿@model NationalIT.TempReport
@{
    var lstTripInfo = Model != null ? Model.Temp_Trip_Info != null ? Model.Temp_Trip_Info.ToList() : new List<NationalIT.Temp_Trip_Info>() : new List<NationalIT.Temp_Trip_Info>();
    var lstFuel_Expenses = Model != null ? Model.Temp_Fuel_Expenses != null ? Model.Temp_Fuel_Expenses.ToList() : new List<NationalIT.Temp_Fuel_Expenses>() : new List<NationalIT.Temp_Fuel_Expenses>();
    var lstOperating_Expenses = Model != null ? Model.Temp_Operating_Expenses != null ? Model.Temp_Operating_Expenses.ToList() : new List<NationalIT.Temp_Operating_Expenses>() : new List<NationalIT.Temp_Operating_Expenses>();
    var lstDriver_Expenses = Model != null ? Model.Temp_Split_Expenses != null ? Model.Temp_Split_Expenses.Where(m => m.Index == 1).ToList() : new List<NationalIT.Temp_Split_Expenses>() : new List<NationalIT.Temp_Split_Expenses>();
    var lstOwner_Expenses = Model != null ? Model.Temp_Split_Expenses != null ? Model.Temp_Split_Expenses.Where(m => m.Index == 2).ToList() : new List<NationalIT.Temp_Split_Expenses>() : new List<NationalIT.Temp_Split_Expenses>();
    var lstEscrowLoan = Model != null ? Model.Temp_EscrowLoan != null ? Model.Temp_EscrowLoan.ToList() : new List<NationalIT.Temp_EscrowLoan>() : new List<NationalIT.Temp_EscrowLoan>();
}
<script type="text/javascript">
    $(document).ready(function () {
        // CHeck toàn bộ khi load
        $("input[type=checkbox]").prop('checked', true);

        // trip
        ListenerCheckBox($("#TripAmountTable .DriverTripCheckAll"), $("#TripAmountTable .DriverTripCheckItem"));
        //fuel expenses
        ListenerCheckBox($("#Fuel_ExpensesAmount .DriverFuel___ExpensesAll"), $("#Fuel_ExpensesAmount .DriverFuel___ExpensesItem"));
        //operating expenses
        ListenerCheckBox($("#Operating_ExpensesAmount .DriverOperating_ExpensesAll"), $("#Operating_ExpensesAmount .DriverOperating_ExpensesItem"));
        //Driver split expenses
        ListenerCheckBox($("#DriverExpensesSplit .SplitcheckAll"), $("#DriverExpensesSplit .Splitcheckitem"));
        //Owner split expenses
        ListenerCheckBox($("#OwnerExpensesSplit .SplitcheckAll"), $("#OwnerExpensesSplit .Splitcheckitem"));
        //Escrow Loan
        ListenerCheckBox($("#Escrow .EscrowcheckAll"), $("#Escrow .Escrowcheckitem"));

        $(".btnRollBack").on("click",function () {
            if (confirm("Are you sure you want process this Roll Back?")) {
                var Trips = getListIDCheckBoxByIDClassName("TripAmountTable", "DriverTripCheckItem");
                var Fuel = getListIDCheckBoxByIDClassName("Fuel_ExpensesAmount", "DriverFuel___ExpensesItem");
                var operating = getListIDCheckBoxByIDClassName("Operating_ExpensesAmount", "DriverOperating_ExpensesItem");
                var splitdriver = getListIDCheckBoxByIDClassName("DriverExpensesSplit", "Splitcheckitem");
                var splitowner = getListIDCheckBoxByIDClassName("OwnerExpensesSplit", "Splitcheckitem");
                var escrowLoan = getListIDCheckBoxByIDClassName("Escrow", "Escrowcheckitem");

                var id = '@(Model != null ? Model.ID : 0)';
                var url = $(this).attr('href');
                var newurl = addParam(addParam(addParam(addParam(addParam(addParam(addParam(url, "escrowLoan", escrowLoan), "id", id), "Trips", Trips), "Fuel", Fuel), "operating", operating), "splitdriver", splitdriver), "splitowner", splitowner);
                if (isRollBackAll()) {
                    newurl = addParam(newurl, "isRollBackAll", true);
                }
                location.href = newurl;
            }
            return false;
        });
    });
    function ListenerCheckBox(objCheckAll, objCheckItem) {
        objCheckItem.click(function () {
            var $this = $(this);
            if ($this.is(':checked')) {
                var countChecked = 0;
                objCheckItem.each(function () {
                    if ($(this).is(":checked")) {
                        countChecked++;
                    }
                });
                if (countChecked == objCheckItem.length) {
                    objCheckAll.prop('checked', true);
                }
            } else {
                objCheckAll.prop('checked', false);
            }
        });
        ListenerCheckAll(objCheckAll, objCheckItem);
    }
    function ListenerCheckAll(checkAll, checkItem) {
        checkAll.click(function () {
            if ($(this).is(':checked')) {
                checkItem.prop('checked', true);
            } else {
                checkItem.prop('checked', false);
            }
        });
    }
    function formatCurrency(num) {
        num = isNaN(num) || num === '' || num === null ? 0.00 : num;
        return parseFloat(num).toFixed(2).replace(/\d(?=(\d{3})+\.)/g, '$&,');
    }
    function isRollBackAll() {
        return $(".DriverTripCheckAll").is(":checked") && $(".DriverFuel___ExpensesAll").is(":checked") && $(".DriverOperating_ExpensesAll").is(":checked") && $("#DriverExpensesSplit .SplitcheckAll").is(":checked") && $("#OwnerExpensesSplit .SplitcheckAll").is(":checked");
    }
</script>
<div id="tab-1-1">
    @Html.Partial("/Views/Undo-Payrolls/_IndexPartialTripInfo.cshtml", lstTripInfo)
</div>
<div id="tab-1-2">
    @Html.Partial("/Views/Undo-Payrolls/_Fuel_ExpensesPartial.cshtml", lstFuel_Expenses)
</div>
<div id="tab-1-3">
    @Html.Partial("/Views/Undo-Payrolls/_Operating_ExpensesPartial.cshtml", lstOperating_Expenses)
</div>
<div id="tab-1-4-1">
    @Html.Partial("/Views/Undo-Payrolls/_DriverExpenses.cshtml", lstDriver_Expenses)
</div>
<div id="tab-1-4-2">
    @Html.Partial("/Views/Undo-Payrolls/_OwnerExpenses.cshtml", lstOwner_Expenses)
</div>
<div id="tab-1-5">
    @Html.Partial("/Views/Undo-Payrolls/_EscrowPartial.cshtml", lstEscrowLoan)
</div>
